package org.systemsbiology.addama.sequencing.util;

import java.util.Hashtable;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: jlin
 * Date: Apr 22, 2010
 * Time: 6:09:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class TranslateSlimSeq {
    //samplePrep
    static protected HashMap samplePrepHash = new HashMap();
    static protected HashMap projectHash = new HashMap();
    static protected HashMap elandParamHash = new HashMap();
    static protected HashMap refGenomeHash = new HashMap();
    static protected HashMap platformHash = new HashMap();
    static protected HashMap primerHash = new HashMap();
    static protected HashMap readFormatHash = new HashMap();

    public static String getSamplePrepId(String samplePrepStr) {
        /*
        ['1', 'ChIP-Seq'],
            ['2', 'Tag Profiling NlaIII'],
            ['3', 'Tag Profiling DpnII'],
            ['4', 'Genomic DNA'],
            ['5', 'Small RNA'],
            ['6', 'Phix Control'],
            ['7', 'NucleosomeSeq'],
            ['8', 'mRNASeq'],
            ['9', 'Dudley Paired End'],
            ['10', 'Genomic DNA Multiplex RAD'],
            ['11', 'Genomic DNA Paired End Multiplex RAD']
         */

        samplePrepHash.put("ChIP-Seq", "1");
        samplePrepHash.put("Tag Profiling NlaIII", "2");
        samplePrepHash.put("Tag Profiling DpnII", "3");
        samplePrepHash.put("Genomic DNA", "4");
        samplePrepHash.put("Small RNA", "5");
        samplePrepHash.put("Phix Control", "6");
        samplePrepHash.put("NucleosomeSeq", "7");
        samplePrepHash.put("mRNASeq", "8");
        samplePrepHash.put("Dudley Paired End", "10");
        samplePrepHash.put("Genomic DNA Multiplex RAD", "11");
        samplePrepHash.put("Genomic DNA Paired End Multiplex RAD", "12");

        return (String) samplePrepHash.get(samplePrepStr);
    }

    /*
    ['19', 'Dudley Fluffy'],
            ['33', 'Dudley Multiplex RAD'],
            ['30', 'Dudley Paired End'],
            ['6',  'Dudley RM-11'],
            ['15', 'Dudley RNA Detection']
     */
    public static String getProjectId(String projStr) {
        projectHash.put("Dudley Natural Variation", "19");
        projectHash.put("Dudley NV Multiplex RAD", "33");
        projectHash.put("Dudley NV Paired End", "30");
        projectHash.put("Dudley RM-11", "6");
        projectHash.put("Dudley RNA Detection", "15");
        return (String) projectHash.get(projStr);
    }

    /*
    "\"platform_id\": \"" + jsonObject.getString("slider") + "\",";
     */
    public static String getPlatformId(String projStr) {
        platformHash.put("Illumina", "1");
        platformHash.put("SOLiD", "2");
        return (String) platformHash.get(projStr);
    }


    /*
    "\"platform_id\": \"" + jsonObject.getString("slider") + "\",";
     */
    public static String getReadFormatId(String projStr) {
        readFormatHash.put("Single", "1");
        readFormatHash.put("PairedEnd", "2");
        return (String) readFormatHash.get(projStr);
    }


    /*
['Genomic DNA Sequencing Primer','Genomic DNA Sequencing Primer'],
['Small RNA Sequencing Primer','Small RNA Sequencing Primer'],
['DpnII Gex Sequencing Primer','DpnII Gex Sequencing Primer'],
['NlaIII Gex Sequencing Primer','NlaIII Gex Sequencing Primer']     */
    public static String getPrimerId(String projStr) {
        primerHash.put("Genomic DNA Sequencing Primer", "1");
        primerHash.put("DpnII Gex Sequencing Primer", "2");
        primerHash.put("NlaIII Gex Sequencing Primer", "3");
        primerHash.put("Small RNA Sequencing Primer", "4");

        return (String) primerHash.get(projStr);
    }

    /*
    Dudley Lab will always use default Eland
    ['1', 'Default'],
           ['2', 'Aderem Lab']
    */
    public static String getElandParamId() {
        /*
        elandParamHash.put("Default", "1");
        elandParamHash.put("Aderem Lab", "2");
        return (String) elandParamHash.get(str);
        */
        return "1";
    }

    /*
    ['Yeast S288C', '1'],
           ['Yeast rm11-1a', '2'],
           ['Human NCBI', '3'],
           ['HPhix', '4'],
           ['Mouse mm9', '5'],
    */
    public static String getRefGenomeId(String str) {
        refGenomeHash.put("Yeast S288C", "4");
        refGenomeHash.put("Yeast rm11-1a", "5");
        refGenomeHash.put("Human NCBI", "2");
        refGenomeHash.put("HPhix", "3");
        refGenomeHash.put("Mouse mm9", "1");
        return (String) refGenomeHash.get(str);
    }

    public String translateSamples(String baseUrl, String yseqName, String samples, String comments) {
        //samples value: YPG200 YPG201
        String[] sampleArray = samples.split(" ");
        if (sampleArray.length == 1) {
            SlimseqSample ss = new SlimseqSample(baseUrl, yseqName, samples, comments);
            return "{" + ss.getNameOnTube() + "," + ss.getSampleDesc() + "," + ss.getComment() + "," + ss.getPostbackUri() + "}";
            //return "{" + ss.getNameOnTube() + "," + ss.getSampleDesc() + "," + ss.getPostbackUri() + "}";
        } else {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < sampleArray.length; i = i + 1) {
                SlimseqSample ss = new SlimseqSample(baseUrl, yseqName, sampleArray[i], comments);
                sb.append("{" + ss.getNameOnTube() + "," + ss.getSampleDesc() + "," + ss.getComment() + "," + ss.getPostbackUri() + "},");
            }
            String ssString = sb.toString();
            return ssString.substring(0, ssString.length() - 1);
        }
    }


    class SlimseqSample {
        /*
        "\"samples\":[" +
                        "{\"name_on_tube\": \"YSEQ_YO_001_Test\", \"sample_description\": \"YO_9001_Test\", " +
                        "\"postback_uri\":\"/addama-rest/dudley-sample/path/datasource/YSEQ/YSEQ_1/YO_901_Test\"}]}}";
         */
        private String nameOnTube;
        private String sampleDesc;
        private String comment;
        private String postbackUri;

        //http://ravioli:8080/dudley-lims/sequencing/samplestatus/YSEQ1
        SlimseqSample(String baseUrl, String yseq, String sampleName, String notes) {
            nameOnTube = "\"name_on_tube\":\"" + yseq + "_" + sampleName + "\"";
            sampleDesc = "\"sample_description\":\"" + sampleName + "\"";
            comment = "\"comment\":\"" + notes + "\"";
            postbackUri = "\"postback_uri\":\"" + baseUrl + getAddamaYSEQPath() + yseq + "\"";

        }

        private String getAddamaYSEQPath() {
            //return "/addama-rest/dudley-sample/path/datasource/YSEQ/";
            return "/dudley-lims/sequencing/samplestatus/";
        }

        public String getNameOnTube() {
            return nameOnTube;
        }

        public String getSampleDesc() {
            return sampleDesc;
        }

        public String getComment() {
            return comment;
        }

        public String getPostbackUri() {
            return postbackUri;
        }

    }

}
